package com.xxx.course.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xxx.course.common.Result;
import com.xxx.course.entity.EduSubject;
import com.xxx.course.entity.subject.ParentSubject;
import com.xxx.course.service.EduSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author chn
 * @since 2022-05-29
 */
@RestController
@RequestMapping("/subject")
@CrossOrigin
public class EduSubjectController {
    @Autowired
    private EduSubjectService subjectService;

    @GetMapping("/tree")
    public Result tree(){
        List<ParentSubject> list= subjectService.listTree();
        return Result.ok().data("list",list);
    }
    @GetMapping("/getParent")
    public Result getParent(){
        List<EduSubject> list = subjectService.list(new QueryWrapper<EduSubject>().eq("parent_id", 0));
        return Result.ok().data("parent",list);
    }
    @GetMapping("/getChild/{id}")
    public Result getParent(@PathVariable String id){
        List<EduSubject> list = subjectService.list(new QueryWrapper<EduSubject>().eq("parent_id", id));
        return Result.ok().data("child",list);
    }
}

